/*
  将下面异步代码使用 Promise 的方法改进
  尽量用看上去像同步代码的方式
  setTimeout(function () {
    var a = 'hello'
    setTimeout(function () {
      var b = 'lagou'
      setTimeout(function () {
        var c = 'I ♥ U'
        console.log(a + b +c)
      }, 10)
    }, 10)
  }, 10)
*/

const timeout = (ms) => {
  return (v) => new Promise(resolve => setTimeout(() => resolve(v), ms))
}

const fn1 = async () => {
  const timeout10 = timeout(10);

  const a = await timeout10('hello');
  const b = await timeout10('lagou');
  const c = await timeout10('I ♥ U')

  console.log('fn1 ------>', a + b + c);
};

fn1()


const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));

const fn2 = () => new Promise(async (resolve) => {
    await sleep(10);
    const str = ['hello'];

    resolve(str);
  })
  .then(async (v) => {
    await sleep(10);

    v.push('lagou')
    return v
  })
  .then(async (v) => {
    await sleep(10);

    v.push('I ♥ U');
    return  v
  })
  .then(v => {
    console.log('fn2 ------>', v.join(''))
  });

fn2()